package org.yumeko.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

// 消费者类型分 PushConsumer SimpleConsumer 以及 PullConsumer 三种
@Configuration
public class MessageConsumer {

    @Slf4j
    @Component
    @RocketMQMessageListener( topic = "TopicZero", consumerGroup = "ConsumerGroup")
    public static class MyConsumer0 implements RocketMQListener<String> {
        public void onMessage(String message) {
            log.info("received message: {}", message);
        }
    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener( topic = "TopicOne", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer1 implements RocketMQListener<String> {
//        public void onMessage(String message) {
//            log.info("received message: {}", message);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener( topic = "TopicTwo", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer2 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            String body = new String(message.getBody(), StandardCharsets.UTF_8);
//            log.info("Received message body: {}", body);
//            // 获取自定义头部
//            String headerValue = message.getUserProperty("headerKey");
//            if (headerValue != null) {
//                log.info("Received custom header 'headerKey': {}", headerValue);
//            } else {
//                log.warn("Custom header 'headerKey' not found in the received message.");
//            }
//        }
//    }
//
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicThree", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer3 implements RocketMQListener<MessageExt> {
//
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息ID
//            String messageId = message.getMsgId();
//            log.info("Received message ID: {}", messageId);
//            // 获取消息体
//            String body = new String(message.getBody(), StandardCharsets.UTF_8);
//            log.info("Received message body: {}", body);
//            // 获取KEYS属性
//            String keys = message.getKeys();
//            log.info("Received keys: {}", keys);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicFour", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer4 implements RocketMQListener<MessageExt> {
//
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息ID
//            String messageId = message.getMsgId();
//            log.info("Received message ID: {}", messageId);
//            // 获取消息体
//            String body = new String(message.getBody(), StandardCharsets.UTF_8);
//            log.info("Received message body: {}", body);
//            // 获取KEYS属性
//            String keys = message.getKeys();
//            log.info("Received keys: {}", keys);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicFive", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer5 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received orderly message body: {}", body);
//
//            // 获取队列ID，确认消息是否按顺序接收
//            int queueId = message.getQueueId();
//            log.info("Received message from queue ID: {}", queueId);
//        }
//    }
//
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicSix", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer6 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicSeven", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer7 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicEight", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer8 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicNine", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer9 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicTen", consumerGroup = "OrderConsumerGroup")
//    public static class MyConsumer10 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicEleven", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer11 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicTwelve", consumerGroup = "OrderConsumerGroup")
//    public static class MyConsumer12 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
//    @Slf4j
//    @Component
//    @RocketMQMessageListener(topic = "TopicThirteen", consumerGroup = "ConsumerGroup")
//    public static class MyConsumer13 implements RocketMQListener<MessageExt> {
//        @Override
//        public void onMessage(MessageExt message) {
//            // 获取消息体
//            String body = new String(message.getBody());
//            log.info("Received concurrently message body: {}", body);
//        }
//    }
}
